// packageD/mycomponent/city_delivery_day/city_delivery_day.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    popShow:false,
    day_list:[],
    day_index:0,
    time_list:[],
    time_index:null
  },

  /**
   * 组件的方法列表
   */
  methods: {
    setPopShow(){
      this.setData({
        popShow:!this.data.popShow
      });
    },
    setListData(arr,default_choose=0){
      if(arr.length==0) return;
      this.setData({
        day_list:arr,
        time_list:arr[0].time_arr
      });
      //开启默认选择最近时间
      if(default_choose==1){
        this.setDayIndex(0);
        this.setTimeIndex(0);
        this.confirm();
      }
    },
    setDayIndex(evt){
      let index = evt.currentTarget ? evt.currentTarget.dataset.index : evt;
      if(this.data.day_index == index) return;
      this.setData({
        day_index:index,
        time_index:null,
        time_list:this.data.day_list[index].time_arr
      });
    },
    setTimeIndex(evt){
      let index = evt.currentTarget ? evt.currentTarget.dataset.index : evt;
      this.setData({
        time_index:index
      });
    },
    confirm(evt=null){
      if(this.data.time_index == null) return;
      let time = this.data.time_list[this.data.time_index];
      time.day = this.data.day_list[this.data.day_index].day;
      this.triggerEvent("confirm",time);
      if(evt!=null){
        this.setPopShow();
      }
     
    }
  }
});
